package com.leetao.netty.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 簡單通道处理者
 * @author 菅江晖
 * @date 2021/4/16 - 8:48
 */
@Component
public class SimpleChannelHandler extends SimpleChannelAdapter {



    @Override
    public void connected(ChannelHandlerContext ctx) {
        //TODO 已连接执行的逻辑
        System.out.println("已连接");
    }

    @Override
    public void init(Channel channel, FullHttpRequest fullRequest, Map<String, List<String>> params) {
        //TODO 第一次连接，FullHttpRequest的逻辑
        System.out.println("初始化");
    }

    @Override
    public void message(Channel channel, String msg) {
        System.out.println("收到消息");
        this.send(channel,"ok");
    }



    @Override
    public void exception(ChannelHandlerContext ctx, Throwable cause) {
        //TODO 发生异常的逻辑
        System.out.println("发生异常");
    }

    @Override
    public void disconnected(Channel channel) {
        //TODO 关闭连接的逻辑
        System.out.println("断开连接");
    }

    @Override
    public void close(ChannelHandlerContext ctx) {
        //TODO 通道关闭的逻辑
        System.out.println("删除通道");
    }

}
